package cn.iocoder.yudao.module.vote.dal.mysql.voterecorddetail;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.vote.controller.admin.voterecord.vo.VoteRecordPageReqVO;
import cn.iocoder.yudao.module.vote.dal.dataobject.voterecorddetail.VoteRecordDetailDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.vote.controller.admin.voterecorddetail.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 投票记录详情 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface VoteRecordDetailMapper extends BaseMapperX<VoteRecordDetailDO> {

    default PageResult<VoteRecordDetailDO> selectPage(VoteRecordDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VoteRecordDetailDO>()
                .eqIfPresent(VoteRecordDetailDO::getIp, reqVO.getIp())
                .eqIfPresent(VoteRecordDetailDO::getVoteId, reqVO.getVoteId())
                .likeIfPresent(VoteRecordDetailDO::getVoteName, reqVO.getVoteName())
                .likeIfPresent(VoteRecordDetailDO::getUserName, reqVO.getUserName())
                .eqIfPresent(VoteRecordDetailDO::getUserResultId, reqVO.getUserResultId())
                .eqIfPresent(VoteRecordDetailDO::getRecordId, reqVO.getRecordId())
                .betweenIfPresent(VoteRecordDetailDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(VoteRecordDetailDO::getId));
    }

    default List<VoteRecordDetailDO> selectList(VoteRecordDetailExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<VoteRecordDetailDO>()
                .eqIfPresent(VoteRecordDetailDO::getIp, reqVO.getIp())
                .eqIfPresent(VoteRecordDetailDO::getVoteId, reqVO.getVoteId())
                .likeIfPresent(VoteRecordDetailDO::getVoteName, reqVO.getVoteName())
                .likeIfPresent(VoteRecordDetailDO::getUserName, reqVO.getUserName())
                .eqIfPresent(VoteRecordDetailDO::getUserResultId, reqVO.getUserResultId())
                .eqIfPresent(VoteRecordDetailDO::getRecordId, reqVO.getRecordId())
                .betweenIfPresent(VoteRecordDetailDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByAsc(VoteRecordDetailDO::getVoteReviewerType)
                .orderByAsc(VoteRecordDetailDO::getUserName));
    }


    List<VoteRecordCountVO> countVoteRecord(Integer voteId);

    /**
     *
     * @param voteId
     * @param userResultId
     * @param votePersonType
     * @return
     */
    List<VoteRecordCountVO> getByResultId(@Param("voteId")Integer voteId,@Param("userResultId")Integer userResultId,@Param("votePersonType")Integer votePersonType);

    default int deleteByVoteId(Integer voteId){
        return delete(new LambdaQueryWrapperX<VoteRecordDetailDO>()
            .eq(VoteRecordDetailDO::getVoteId,voteId));
    }
    /**
     *
     * @param voteId
     * @return
     */
    List<VoteRecordDetailVO> getByVoteId(@Param("voteId")Integer voteId);


}
